package com.felix.netty.c1.future;

import io.netty.channel.DefaultEventLoop;
import io.netty.util.concurrent.DefaultPromise;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;


/** 异步处理任务成功 **/
@Slf4j
public class example2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        DefaultEventLoop eventExecutors = new DefaultEventLoop();
        DefaultPromise<Object> promise = new DefaultPromise<>(eventExecutors);

        promise.addListener(future->{
            log.debug("{}",future.getNow());
        });

        eventExecutors.execute(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("set success,{}",10);
            promise.setSuccess(10);
        });

        log.debug("start..");
    }
}
